package cn.itcast.algorithm.exercise;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Stack;

/**
 * 该题目的考点是测试栈的后进先出的数据结构
 * peek 获取栈顶元素 但不删除
 * pop 弹出栈顶元素（删除）
 * push 压栈
 * 左右括号匹配时要点是：即将入栈元素和栈顶元素成对匹配，如果匹配，栈顶元素出栈pop，否则新元素入栈。当栈中元素为空时，表示匹配完毕，数据合法
 * https://www.nowcoder.com/practice/37548e94a270412c8b9fb85643c8ccc2?tpId=308&tqId=726&ru=/exam/oj&qru=/ta/algorithm-start/question-ranking&sourceUrl=%2Fexam%2Foj%3Fpage%3D1%26tab%3D%25E7%25AE%2597%25E6%25B3%2595%25E7%25AF%2587%26topicId%3D308
 * create by zhangtian105 on 2022/5/13
 */
public class ExerciseAB5 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String clearStr = br.readLine();

        clickClear(clearStr);
    }

    /**
     *
     * @param clearStr string字符串
     * @return bool布尔型
     */
    public static void clickClear (String clearStr) {
        if (null == clearStr || "".equals(clearStr)) {
            System.out.println(0);
        }

        if (clearStr.length() == 1) {
            System.out.println(clearStr);
        }

        Stack<String> dataStack = new Stack<>() ;
        String[] clearArr = clearStr.split("") ;
        for (int i = 0; i < clearArr.length; i++) {
            String clear = clearArr[i] ;
           if (dataStack.empty()) {
               dataStack.push(clear) ;
           }else {
               String topStr = dataStack.peek() ;
               if (topStr.equals(clear)) {
                   dataStack.pop() ;
               }else {
                   dataStack.push(clear) ;
               }
           }
        }

        if (dataStack.isEmpty()) {
            System.out.println(0);
        }else {
            int size = dataStack.size() ;
            String res = "" ;
            for (int i = 0; i < size; i++) {
                res = dataStack.pop() + res ;
            }

            System.out.println(res);
        }
    }
}
